from aspectlib import Aspect
def authorize(f):
def wrapper(*args, **kwargs):
if kwargs.get('username') == 'admin':
return f(*args, **kwargs)
else:
raise PermissionError("Unauthorized access")
return wrapper
= Aspect().around(authorize)
authorization_aspect
@authorization_aspect
def secret_info(username):
return "This is classified information"
print(secret_info(username='admin')) # Output: This is classified information
print(secret_info(username='user')) # Raises: PermissionError: Unauthorized access
04-24-24 (Wednesday)
Lord, we pray for ourselves in our daily study and work.
We give thanks for the skills we already have; we pray for wise and good use of these skills in building your kingdom.
We pray for those thinking about changing their study and/or work - especially those unhappy or insecure; those feeling undervalued or unfulfilled; those feeling that are in the wrong place; those who can’t wait for 5pm on Friday.
We pray for those with no sense of direction or purpose or vocation, for those drifting,
for those wanting to do a particular job, but unable through disability, illness, lack of confidence or lack of opportunity;
for those who are unemployed.
We pray for those at school or college now making decisions which will affect our working lives. We pray for all Careers Advisers.
We pray for those who are teaching us;
for our colleagues,
for our administrators.
1 Other programming paradigms
- We have seen basic declarative programming and object-oriented programming. But there are lots of other ways to develop a code…
1.1 Functional programming
- Computation is understood as just the evaluation of mathematical functions. Therefore, it avoids changing-state and mutable data.
- Example of languages commonly used in the functional paradigm are Lisp and Haskell.
- For example, in Lisp, in order to calculate the expression \((2 * cos(0) * (4 + 6))\), you would type:
(* 2 (cos 0) (+ 4 6))
- This paradigm is used a lot in areas such as:
- Data processing (transformation, filtering, and aggregation of data)
- Finances (quantitative analysis, risk management, and algorithmic trading)
- Scientific computing (numerical analysis, simulations, and modeling)
- AI in games
1.2 Aspect-Oriented programming
- Aims to increase modularity by allowing the separation of cross-cutting concerns
- For example, logging, security, or transaction management - would you need to write code for doing that every time it is needed?
- AOP provides a solution: adding a decorator to a function establishing that it needs to “pass” through a certain aspect.
1.3 Parallel programming
- Allows multiple tasks to run concurrently, potentially speeding up the execution of programs that can be divided into smaller tasks that can be executed simultaneously.
- There are lots of libraries and approaches to that. For example, in Python, you can do:
import multiprocessing
def square(x):
return x**2
if __name__ == '__main__':
= [1, 2, 3, 4, 5]
numbers with multiprocessing.Pool() as pool:
= pool.map(square, numbers)
squared print(squared)
# Output: [1, 4, 9, 16, 25]
1.4 Reflective programming
- Allows a program to examine and modify its own structure and behavior at runtime.
- It is often used for debugging, testing, and frameworks that require runtime information about classes and objects.
- For example, I can add methods to a Python class during runtime:
class MyClass:
def __init__(self, x):
self.x = x
def new_method(self):
return f"New method called with x={self.x}"
# Add a new method to MyClass at runtime
= new_method
MyClass.new_method
# Create an instance of MyClass
= MyClass(5)
obj
# Call the new method
print(obj.new_method())
2 Programming and virtues
- The last decades have seen a resurgence on the discussion of virtues in academic scholarship: G. E. M. Anscombe, Philippa Foot, John McDowell, Rosalind Hursthouse and Alasdair MacIntyre
- Thinking about virtues help us to go beyond the limitations of an ethics of duty (deontological) and an ethics of utility (utilitarianism)
- The focus is not in the actions of someone, but in the individual himself, seen as situated inside a narrative and a social practice
- According to Alasdair MacIntyre, every social practice has standards of excellence (or constitutive rules) that guarantee their “internal goods”. These are the virtues.
- Individuals show virtues inside these practices as they insert them inside a big narrative unity of life.
- Programming is a kind of social practice. What are its virtues?
2.1 What are virtues?
- From the Latin virtus, associated with the Greek arête, which means “excellence”. Aristotle used this term to talk about “moral virtues”, i.e., the excellences of character.
- It is possible to identify different virtue traditions:
Judaism | Aristotelianism | Confucianism | Buddhism | |
---|---|---|---|---|
The idea of the supreme good | Shalom | Eudaimonia | Dao | Nirvana |
The exemplary virtuous person | Makarios (blessed), Tsadic (righteous) | Phronimoi | Junzi | Sangha |
The way to moral growth | Torah (ex.: Psalm 119) | Phronesis | Li (moral rites) | The Noble Eightfold Path |
Who is moral human being | Tselem Elohim (image of God) | Political and rational animal | Xing (many strands) | Anatman, pratitya-samutpada |
- There are similarities, but also some fundamental differences. They also identify different fundamental virtues:
Aristotelianism | Christianity | Confucianism | Buddhism |
---|---|---|---|
Courage Temperance Liberality Magnificence Magnanimity Ambition Patience Friendship Honesty Good mood Modesty Justice |
The Beatitudes (Matthew 5:1-12) The four cardinal virtues: - Justice - Prudence - Courage - Temperance The three theological virtues: - Faith - Hope - Love |
Loyalty (Zhong) Filial piety (Xiao) Benevolence (Ren) Affection (Ai) Honesty (Xin) Righteousness (Yi) Harmony (He) Peace (Ping) Respect (Li) Wisdom (Zhi) Integrity (Lian) Shame (Chi) |
The “perfections” (Pāramitās): Dāna (generosity) Sīla (appropriate conduct) Nekkhamma (renouncement) Paññā (wisdom) Viriya (energy) Khanti (patience) Sacca (honesty) Adhiṭṭhāna (determination) Mettā (good will) Upekkhā (tranquility) |
“The Tao, which others may call Natural Law or Traditional Morality or the First Principles of Practical Reason or the First Platitudes, is not one among a series of possible systems of value. It is the sole source of all value judgments. If it is rejected, all value is rejected. If any value is retained, it is retained. The effort to refute it and raise a new system of value in its place is self-contradictory. There has never been, and never will be, a radically new judgment of value in the history of the world. What purport to be new systems or…ideologies…all consist of fragments from the Tao itself, arbitrarily wrenched from their context in the whole and then swollen to madness in their isolation, yet still owing to the Tao and to it alone such validity as they posses.” ― C.S. Lewis, The Abolition of Man
2.2 Intellectual virtues
- Lots of development today in the area of virtues that need to be present in our search for truth. See, for example, this book.
Virtues | Vices |
---|---|
Curiosity Perceptiveness Discernment Honesty Integrity Autonomy Humility Parsimony Perseverance Justification Depth Empathy/Benevolence Creativity |
Curiosity Indifference Naivety Dishonesty Corruption Dogmatism Self-deception Diffusivity Obstination Wishful thinking Superficiality Obtuseness/Stupidity Closemindedness |
2.3 The technomoral virtues (Shannon Vallor)
- Philosopher Shannon Vallor has discussed the need of virtues that are adequate for our current technological society.
Virtue | Related Virtues | Technological Issue |
---|---|---|
1. Honesty | Trust, integrity | New forms of communication |
2. Self-control | Temperance, discipline, moderation | New temptations (media, entertainment) |
3. Humility | Modesty, reverence, wonder | Optimism or pessimism regarding progress |
4. Justice | Responsibility, equity, reciprocity | Who receives benefits and harms from technological advancement |
5. Courage | Hope, perseverance, fortitude | Risks are greater, on a global level |
6. Empathy | Compassion, benevolence, sympathy | Media that encourages indifference and virulence |
7. Care | Generosity, love, self-sacrifice, charity | Delegation of tasks to machines can eliminate human contact |
8. Civility | Respect, commitment, friendship | Individualism and fragmentation into bubbles |
9. Flexibility | Patience, indulgence, tolerance, mercy | Pluralism and globalization |
10. Perspective | Discernment, attention, understanding | Division of labor makes it difficult to visualize short- and long-term impacts |
11. Magnanimity | Equanimity, courage, ambition | Lack of leadership to deal with impacts |
12. Wisdom | Unifies all others |
2.4 How does one grow in virtues?
- Vallor also calls attention to some common steps predicated by the virtue traditions that indicate moral growth:
- Moral habituation: repetition, memorization, observation of exemplary people, ascetic discipline
- Relational understanding: discern my role, my position and my duties in the context I find myself (child, parent, citizen, etc.)
- Reflective self-examination: “Search me, O God, and know my heart! Try me and know my thoughts! And see if there be any grievous way in me, and lead me in the way everlasting!” (Psalm 139.23-24)
- Intentional self-direction of moral development: a resolution to improve, and seeking for help. “With my whole heart I seek you; let me not wander from your commandments!” (Psalm 119.10)
- Moral attention and discernment: sensitivity to discern “morally salient” characteristics of a circumstance.
- Prudential judgment (phronesis): ability to deliberate and adapt principles and rules to the situation (which may be new and unforeseen). Example: Jesus healed in the Sabbath.
- Appropriate extent of moral concern: “who is my neighbor?” Remember the parable of the good samaritan. To know how to be concerned with the right people, in the right time, in the right degree, in the right way”.
2.5 Analysing programming practice
- What are the virtues we tried to practice this semester?
- Try to go to our content and discern them. Use a list of virtues of a tradition and try to see them there.
- What are some possible vices in the programming practice? How can we act to counteract them?
- How to develop myself as a virtuous programmer?
3 More project pitching!
What is the project about?
What is the main problem-solving challenge?
Algorithm design, game design, GUI design, data structure design, etc
What is the main coding challenge?
Use of an external module, such as textblob, turtle, guizero, use of try-except, etc